package com.demo.service.impl;

import com.demo.dao.OrderExpandDao;
import com.demo.model.OrderExpand;
import com.demo.service.OrderExpandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderExpandServiceImpl implements OrderExpandService {
    @Autowired
    private OrderExpandDao orderExpandDao;

    @Override
    public int save(OrderExpand orderExpand) {
        return orderExpandDao.insert(orderExpand);
    }

    @Override
    public OrderExpand getOrderExpandById(Integer id) {
        return orderExpandDao.selectOne(id);
    }
    @Override
    public OrderExpand getOrderExpandByOrderId(Integer orderId) {
        return orderExpandDao.selectOneByOrderId(orderId);
    }

    @Override
    public Integer updateOrderExpand(OrderExpand orderExpand) {
        if (orderExpand.getId() != null && orderExpand.getId() > 0) {
            return orderExpandDao.update(orderExpand);
        }
        return orderExpandDao.insert(orderExpand);
    }

    @Override
    public Integer deleteOrder(int id) {
        return orderExpandDao.delete(id);
    }

    @Override
    public List<OrderExpand> getOrders(Integer productId) {
        return orderExpandDao.select(productId);
    }


}
